package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.pojo.R;
import com.zhentao.pojo.ClosureNotice;
import com.zhentao.service.ClosureNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/closure-notice")
public class ClosureNoticeController {

    @Autowired
    private ClosureNoticeService closureNoticeService;

    /**
     * 获取所有停诊通知（按发布时间倒序）
     */
    @GetMapping("/all")
    public R<List<ClosureNotice>> getAllNotices() {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }

    /**
     * 获取生效中的停诊通知
     */
    @GetMapping("/active")
    public R<List<ClosureNotice>> getActiveNotices() {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .eq(ClosureNotice::getStatus, "active")
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }

    /**
     * 按科室获取停诊通知
     */
    @GetMapping("/by-department")
    public R<List<ClosureNotice>> getNoticesByDepartment(@RequestParam String department) {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .eq(ClosureNotice::getDepartment, department)
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }

    /**
     * 按医生获取停诊通知
     */
    @GetMapping("/by-doctor")
    public R<List<ClosureNotice>> getNoticesByDoctor(@RequestParam String doctor) {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .eq(ClosureNotice::getDoctor, doctor)
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }

    /**
     * 获取单个停诊通知详情
     */
    @GetMapping("/{id}")
    public R<ClosureNotice> getNoticeById(@PathVariable Long id) {
        return R.ok(closureNoticeService.getById(id));
    }

    /**
     * 按优先级获取停诊通知
     */
    @GetMapping("/by-priority")
    public R<List<ClosureNotice>> getNoticesByPriority(@RequestParam String priority) {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .eq(ClosureNotice::getPriority, priority)
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }

    /**
     * 按通知类型获取停诊通知
     */
    @GetMapping("/by-type")
    public R<List<ClosureNotice>> getNoticesByType(@RequestParam String noticeType) {
        LambdaQueryWrapper<ClosureNotice> qw = new LambdaQueryWrapper<>();
        qw.eq(ClosureNotice::getDeleted, 0)
          .eq(ClosureNotice::getNoticeType, noticeType)
          .orderByDesc(ClosureNotice::getPublishTime);
        return R.ok(closureNoticeService.list(qw));
    }
}
